/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package radiopatrulla;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author host
 */
public class miPanel extends javax.swing.JPanel {

    String urlTelefono = "src\\images\\1.jpg";
    int xCasa = (java.awt.Toolkit.getDefaultToolkit().getScreenSize().width) - 200;
    int yCasa = 150;
    int dia = 1;
    int hora = 0;
    int minutos = 0;
    Vector<JLabel> casas = new Vector<JLabel>();
    Vector<Patrulla> autos = new Vector<Patrulla>();
    Timer time;
    Timer telefono;
    RadioPatrulla rp = new RadioPatrulla();
    int horaLlamada = 0;
    int minutoLlamada;
    int aux;

    public miPanel() {
        initComponents();
        this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize().width, java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
        this.setBackground(Color.white);
        cargarDatos();
        aux=(int)rp.tiempoLlamada();
        
        time = new Timer(600, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                jLabel1.setText(dia+":"+hora+":"+minutos);
                while(aux<3){
                    aux=(int)rp.tiempoLlamada();
                }
                minutoLlamada = aux;
                System.out.println("minuto llamada: "+minutoLlamada);
                minutos++;
                if(minutos==minutoLlamada){
                    urlTelefono="src\\images\\2.gif";
                    minutoLlamada +=aux;                    
                }
                else{
                    urlTelefono="src\\images\\1.jpg";
                }
                if(hora==24 && minutos==60){
                    dia++;
                    hora=0;
                    minutos=0;
                }
                if(minutos==60){
                    minutos=0;
                    hora++;
                }
            }
        });
        telefono = new Timer(400, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                urlTelefono = "src\\images\\1.jpg";
                telefono.stop();
            }
        });
    }
    
    public void moverPatrulla(){
        
    }
    
    public void cargarDatos(){
        casas.add(jLabel2);
        casas.add(jLabel3);
        casas.add(jLabel4);
        casas.add(jLabel5);
        casas.add(jLabel6);
        
        for (int i = 0; i < 5; i++) {
                autos.add(new Patrulla());
            }
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(Toolkit.getDefaultToolkit().getImage(urlTelefono), 10, 10, this);
        for (int i = 0; i < autos.size(); i++) {
            g.drawImage(Toolkit.getDefaultToolkit().getImage("src\\images\\2.png"), autos.get(i).getX(), autos.get(i).getY(), this);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        jLabel1.setText("0:0:0");

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/casa.jpg"))); // NOI18N

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/casa.jpg"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/casa.jpg"))); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/casa.jpg"))); // NOI18N

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/casa.jpg"))); // NOI18N

        jButton1.setText("Play");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(206, 206, 206)
                        .addComponent(jLabel1)
                        .addGap(31, 31, 31)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 431, Short.MAX_VALUE)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3))))
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jButton1)))
                    .addComponent(jLabel2))
                .addGap(16, 16, 16)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addContainerGap(35, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(jButton1.getText().equals("Play")){
            jButton1.setText("Stop");
            time.start();
        }
        else{
            jButton1.setText("Play");
            time.stop();
        }
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables
}
